package com.beyond.core.handler;

import com.beyond.core.common.EscapeTool;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ProofTimeHandler extends SimpleChannelInboundHandler<DatagramPacket> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) throws Exception {
        ByteBuf content = datagramPacket.content();
        byte[] bytes=new byte[content.readableBytes()];
        content.readBytes(bytes);

        //如果有转义字符存在
        byte[] responseData = EscapeTool.reverseEscapeData(bytes);
        byte opType = responseData[2];
        if (opType != 0x84){
            //TODO 后续处理
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
        cause.printStackTrace();
        log.debug("定时任务通道异常");
        ctx.close();
    }
}
